import { HashRouter as Router, Route, Redirect, Switch } from 'react-router-dom'
import Center from '../views/Center'
import Films from '../views/Films'
import Cinemas from '../views/Cinemas'
import Detail from '../views/Detail'
import Login from '../views/Login'
import City from '../views/City'
import Search from '../views/Search'

import React, { Component } from 'react'
import NotFound from '../views/NotFound'

function isAuth() {
    return localStorage.getItem('token')
}

export default class IndexRouter extends Component {
    render() {
        return (
            <Router>
                {this.props.children}
                <Switch>
                    <Route path="/films" component={Films} />
                    <Route path="/cinemas" component={Cinemas} exact />
                    <Route path="/cinemas/search" component={Search} exact />

                    {/* <Route path="/center" component={Center} /> */}
                    <Route path="/center" render={() => {
                        return isAuth() ? <Center /> : <Redirect to="/login" />
                    }} />
                    {/* <Route path="/detail/" component={Detail} /> */}
                    <Route path="/detail/:filmId" component={Detail} />

                    <Route path="/login" component={Login} />
                    <Route path="/city" component={City} />

                    <Redirect from="/" to="/films" exact />
                    <Route path="*" component={NotFound} />
                </Switch>
            </Router>
        )
    }
}
